#ifndef CONNECTION
#define CONNECTION

#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>

static bool createConnection(){
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.drivers();
    db.setHostName("ABC");
    db.setDatabaseName("Mydb");
    db.setUserName("FTICO");
    db.setPassword("1234");
    db.setPort(8080);
    bool ok = db.open();

    if(!db.open()){
        QMessageBox::critical(0, QObject::tr("Database error!"), db.lastError().text());
    }

    QSqlQuery query;
    query.exec("create table Student (ID varchar(10) primary key, "
               "Name varchar(20), Age int, Gender char(7), PhoneNumber int, Email varchar(20))");
    query.exec("insert into Student values('SE01234', 'Nguyen Van A', 18, 'Male', 0123456789, 'Anv@gmail.com')");
    query.exec("insert into Student values('SE01235', 'Tran Thi B', 20, 'Female', 05648235896, 'Btt@gmail.com')");
    query.exec("insert into Student values('SE01236', 'Le Van C', 19, 'Male', 01325469899, 'Clv@gmail.com')");
    query.exec("insert into Student values('SE01237', 'Do Quoc D', 18, 'Male', 0987654321, 'Ddq@gmail.com')");
    query.exec("insert into Student values('SE01238', 'Doan Thi E', 19, 'Female', 0123654879, 'Edt@gmail.com')");

    return true;

    db.close();
}

#endif // CONNECTION

